// mircoApp/kaipin_laboratory/details/details.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    placeholder: "请输入参与数量",
    LastHeight: 0,
    Height: 0,
    apply_status: 0,
    count: null,
    participation_flag: false,
    customer_flag: false,
    flow_flag: false,
    keyword: "",
    active: 0,
    child_active: 0,

    comment_list:[],
    details:{},
    id:"",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.data.id = options.id;
    this.getData();
  },
  lose_focus() {
    this.setData({
      placeholder: ""
    })
  },
  mobile_handle(){
    wx.makePhoneCall({
      phoneNumber:this.data.details.tel
    })
  },
  input_handle(e){
    this.setData({count:e.detail.value});
  },
  back() {
    wx.navigateBack()
  },
  onClickCustomer() {
    console.log("====")
    this.setData({
      customer_flag: true
    })
  },
  imgHeight: function (e) {
    var winWid = wx.getSystemInfoSync().windowWidth; //获取当前屏幕的宽度
    if (e && e.detail) {
      var imgh = e.detail.height; //图片高度
      var imgw = e.detail.width; //图片宽度
      var swiperH = (winWid * imgh) / imgw; //等比设置swiper的高度。 即 屏幕宽度 / swiper高度 = 图片宽度 / 图片高度  ==》swiper高度 = 屏幕宽度 * 图片高度 / 图片宽度
      if (parseInt(swiperH) > this.data.LastHeight) {
        this.setData({
          Height: swiperH, //设置高度
        });
        this.data.LastHeight = parseInt(swiperH);
      }
    }
  },
  popup_handle(e) {
    let field = e.currentTarget.dataset.field;
    this.setData({
      [field]: false
    })
  },
  handle() {
    this.setData({
      flow_flag: true
    })
  },
  goto() {
    wx.navigateTo({
      url: '/mircoApp/kaipin_laboratory/comment/comment?id='+this.data.id,
    })
  },
  onClickButton() {
    if (this.data.details.is_sign_up||this.data.details.status>=1||this.data.details.is_full||this.data.details.status==-1) return;
    this.setData({
      participation_flag: true
    })
  },
  onClickIcon() {
    this.customer_flag = true;
  },
  getData() {
    app._getNetWork({
      url:app.getNetAddresss('plugin.kaipin-laboratory.frontend.product-plaza.get-product-detail'),
      data:{id:this.data.id},
      success:resdata=>{
        let {result,data,msg} = resdata.data;
        if(result){
          console.log(data,'data=');
          let comment_list = data.comment.splice(0,5);
          this.setData({details:data,comment_list});
        }else{
          app.tips(msg);
        }
      }
    })
  },
  confirm() {
    app._postNetWork({
      url:app.getNetAddresss("plugin.kaipin-laboratory.frontend.product-plaza.sign-up"),
      data:{number:this.data.count,id:this.data.id},
      success:resdata=>{
        let {result,msg} = resdata.data;
        app.tips(msg);
        if(result){
          this.setData({participation_flag: false});
          this.getData();
        }
      }
    })
  },
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})